package com.yjt.sousou.create;

import android.view.View;
import android.widget.ImageView;

import androidx.annotation.Nullable;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.yjt.sousou.R;
import com.yjt.sousou.create.entity.ImageItem;

import java.util.List;

/**
 * 作者：83734
 * 时间：2018/11/24
 * 描述：
 */
public class PicRecycleAdapter extends BaseQuickAdapter<ImageItem,BaseViewHolder> {
    private int from;
    public PicRecycleAdapter(int layoutResId, @Nullable List<ImageItem> data) {
        super(layoutResId, data);
    }

    public void setFrom(int from) {
        this.from = from;
    }

    @Override
    protected void convert(BaseViewHolder holder, ImageItem item) {
        ImageView imageView = holder.getView(R.id.item_image);
        ImageView iv_play = holder.getView(R.id.iv_play);
        if (isShowAddItem(holder.getAdapterPosition())) {
            imageView.setImageResource(R.mipmap.add_photo);
            holder.getView(R.id.delete_markView).setVisibility(View.GONE);
        } else {
            Glide.with(mContext)
                    .asBitmap()
                    .load(from==0?item.getPicUri():item.getThumbUrl())
                    .into(imageView);
            if(item.isVideo()){
                iv_play.setVisibility(View.VISIBLE);
            }else {
                iv_play.setVisibility(View.GONE);
            }
        }
    }

    private boolean isShowAddItem(int position) {
        int size = mData == null ? 0 : mData.size();
        return position == size;
    }
}
